package com.aier.entrance.icsocket;

import com.aier.common.common.Constant;


public class WgUdpCommShort { //短报文协议

    public static final int  WGPacketSize = 64;             //报文长度
    public static final byte Type = 0x19;                    //类型
    public static final int  ControllerPort = 60000;        //控制器端口
    public static final long SpecialFlag = 0x55AAAA55;      //特殊标识 防止误操作

    public static byte[] longToByte(long number) {   
        byte[] b = new byte[Constant.num_8];   
        for (int i = 0; i < Constant.num_8; i++) {   
            b[i] = (byte) (number % Constant.num_256);   
            number >>= Constant.num_8;   
        }   
        return b;   
    }
     
     //将带符号的bt转换为不带符号的int类型数据 
    public static int getIntByByte(byte bt)  //bt 转换为无符号的int
    {
        if (bt <0)
        {
            return bt+Constant.num_256;
        }
        else
        {
            return bt;
        }
    }
     
    //从字节转换为 long型数据, 最大长度为8字节 低位在前, 高位在后...
            //bytlen (1--8), 不在此范围则返回 -1
    public static long getLongByByte(byte[] data,int startIndex,int bytlen)
    {
        long ret =-1;
        if ((bytlen >=1) && (bytlen <=Constant.num_8))
        {
            ret = getIntByByte(data[startIndex + bytlen-1]);
            for (int i=1; i<bytlen; i++)
            {
                ret <<=Constant.num_8;
                ret += getIntByByte(data[startIndex + bytlen-1-i]);
            }
        }
        return ret;
    }
            
}
